package com.itheima.exerciseTest.method30_39.method35;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class Demo {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        // 获得系统加载类
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();

        // 加载prop.propertieswe文件
        InputStream is = systemClassLoader.getResourceAsStream("com\\itheima\\exerciseTest\\method30_39\\method35\\prop.properties");

        // 将文件的中的数据读取到集合中
        Properties prop = new Properties();
        prop.load(is);
        is.close();

        System.out.println(prop);

        // 1.获得Class类对象
        Class className = Class.forName(prop.getProperty("className"));

        // 2.获得构造器对象
        Constructor constructor = className.getConstructor();

        // 3.利用构造器创建一个对象
        Object o = constructor.newInstance();

        // 4.获得方法对象
        Method method = className.getDeclaredMethod(prop.getProperty("method"));

        // 5.使用方法
        Object invoke = method.invoke(o);

        // 6.打印返回值
        System.out.println(invoke);


    }
}
